<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
	content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../static/moment/moment.js"></script>
<script src="../static/moment/locale/zh-cn.js"></script>
<script src="../static/js/base-loading.js"></script>
<title>已审核项目列表</title>
</head>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="../app/index.do"></a>
			</div>
			<div class="header-title">已审核项目列表</div>
		</div>

	</div>
	<div class="table-container" data-options="region:'center'">
		<div>
			<div id="pro_tb">
				<div class="search-input" style="text-align: center;">
					<select id="kind" class="easyui-combobox" name="kind" style="width: 180px;"
						data-options="panelHeight:'auto',editable:false">
						<option value="planmain">主计划</option>
						<option value="plandaily">日计划</option>
						<option value="budget">预算</option>
						<option value="urgent">工程联系单</option>
						<option value="capital">资金申请</option>
						<option value="quantities">工程量</option>
						<option value="goods">物资</option>
						<option value="goodscurrent">物资流动</option>
					</select>
				</div>
			</div>
			<table id="pro_table" class="easyui-datagrid" style="min-height: 100%">
			</table>
		</div>

	</div>
	<div style="display: none">
		<div id="displayAtt" class="datagrid-toolbar"
			style="width: 100%; max-height: 80%; padding: 5px; text-align: center;"></div>
	</div>
</body>
<script>
	var currentPro;
	var kind = "";
	$(document).ready(function() {
		$('#pro_table').datagrid({
			rownumbers : false,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			fit : true,
			fitColumns : true,
			striped : true,
			scrollbarSize : 0,
			toolbar : '#pro_tb',
			url : "../planMainReviewed.do",
			method : 'get',
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'name',
				title : '项目',
				width : '100%',
				formatter : function(value,row,index) {
					var str = "";
					str += '<div class="info-unreviewed"><div>'
					if (row.item){
						str += '<div class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.item.name + '</div>';
					}
					str += '<div class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</div>';
					if (row.reason){
						str += '<div class="info-reason">' + row.reason + '</div>';
					}
					str += '</div><div>' + statusCh(row.status) + '</div></div>';
					return str;
				}
			} ] ]
		});
	});
	function statusCh(value) {
		if (value == 4){
			return value = '<div class="info-status ok">已审</div>';
		}else if (value == 3){
			return value = '<div class="info-status refuse">已拒绝</div>';
		}else if (value == 6){
			return value = '<div class="info-status two">待二级审核</div>';
		}else if (value == 7){
			return value = '<div class="info-status one">待一级审核</div>';
		}
	}
	function statusClass(value) {
		if (value == 4){
			return value = 'ok';
		}else if (value == 3){
			return value = 'refuse';
		}else if (value == 6){
			return value = 'two';
		}else if (value == 7){
			return value = 'one';
		}
	}
	function typeCh(value) {
		if (value == 1){
			return value = '加';
		}else if (value == 2){
			return value = '减';
		}
	}
	function ellipsis(value){
		var WIDTH = $("body").width();
		WIDTH-=10;
		var width;
		width = WIDTH-value
		return width;
	}
	$(function() {
		$('#kind').combobox({
			onChange : function(newValue,oldValue) {
				kind = newValue;
				switch(kind){
					case 'planmain':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							scrollbarSize : 0,
							toolbar : '#pro_tb',
							url : "../planMainReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.item){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div></div>';
									return str;
								}
							} ] ]
						});
						break;
					case 'plandaily':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							scrollbarSize : 0,
							toolbar : '#pro_tb',
							url : "../planDailyReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.planMain){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.planMain.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div></div>';
									return str;
								}
							} ] ]
						});
						break;
					case 'budget':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							scrollbarSize : 0,
							toolbar : '#pro_tb',
							url : "../budgetSubItemReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.main){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.main.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div></div>';
									return str;
								}
							} ] ]
						});
						break;
					case 'urgent':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							scrollbarSize : 0,
							toolbar : '#pro_tb',
							url : "../urgentApplyReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.item){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(32) +'px;margin-bottom:10px;">' + row.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div>';
									if (row.attachments.length > 0){
										str += '<div class="edit"><span class="info-more" onclick="viewAtt(' + index + ');"></span></div></div>';
									}else{
										str += '</div>';
									}
									return str;
								}
							} ] ]
						});
						break;
					case 'capital':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							scrollbarSize : 0,
							toolbar : '#pro_tb',
							url : "../capitalApplyReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.item){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.content + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div></div>';
									return str;
								}
							} ] ]
						});
						break;
					case 'quantities':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							toolbar : '#pro_tb',
							url : "../QuantitiesReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.item){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.name + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div>';
									return str;
								}
							} ] ]
						});
						break;
					case 'goods':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							toolbar : '#pro_tb',
							url : "../GoodsReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.item){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + row.name + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div></div>';
									return str;
								}
							} ] ]
						});
						break;
					case 'goodscurrent':
						$('#pro_table').datagrid({
							rownumbers : false,
							singleSelect : true,
							pagination : true,
							fitColumns : false,
							border : false,
							striped : true,
							toolbar : '#pro_tb',
							url : "../GoodsCurrentReviewed.do",
							method : 'get',
							onSelect : function(index,row) {
								currentPro = row;
							},
							columns : [ [ {
								field : 'name',
								title : '项目',
								width : '100%',
								formatter : function(value,row,index) {
									var str = "";
									str += '<div class="info-unreviewed"><div>'
									if (row.goods.item){
										str += '<h4 class="info-item-name" style="width:'+ ellipsis(0) +'px;margin-bottom:10px;">' + row.goods.item.name + '</h4>';
									}
									str += '<p class="info-content" style="width:'+ ellipsis(0) +'px;">' + typeCh(row.type) + row.difference + '</p>';
									if (row.reason){
										str += '<p class="info-reason">拒绝理由：' + row.reason + '</p>';
									}
									str += '</div><div>' + statusCh(row.status) + '</div></div>';
									return str;
								}
							} ] ]
						});
						break;
				}
			}
		});
	});
	
	function viewAtt(index){
		var row = $('#pro_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(isImage(val.url)){
				tb+= '<img onclick="window.open(\'../'+val.url+ 
				'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" '+
				'src="../'+val.url+'" style="width:100px;"><br><span>'+val.name+'</span><br>';
			}else{
				tb+= '<a href="javascript:void(0)" onclick="attachmentFile('+val.id+',\''+val.name+
				'\')"><span>'+val.name+'</span></a><br>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}

	function attachmentFile(id,name) {
		$.get('../attachmentFile.do?id=' + id, function(data) {
			blob = new Blob([ data ])
			var a = document.createElement('a');
			a.download = name;
			a.href = window.URL.createObjectURL(blob)
			a.click()
		})
	}

	function isImage(url) {
		var index= url.lastIndexOf(".");
		var ext = url.substr(index+1);
		return [ 'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff' ,'ico'].
				indexOf(ext.toLowerCase()) !== -1;
	}
</script>
</html>